package com.GB26875_3_2011.config;

import io.netty.channel.EventLoopGroup;
import io.netty.channel.epoll.EpollEventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.util.concurrent.DefaultEventExecutorGroup;
import io.netty.util.concurrent.EventExecutorGroup;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;

import javax.annotation.Resource;
import java.util.Locale;

/**
 * @author 蒋仕国
 * @projectName GB26875_3_211
 * @ClassName GB26875GroupConfig
 * @date 2025-01-13 13:06
 * @Description: TODO []
 */
@Slf4j
public class GB26875GroupConfig {

    @Resource
    private GB26875Properties gB26875Properties;
    public static boolean isLinux() {
        String osName = System.getProperty("os.name").toLowerCase(Locale.ROOT);
        return osName.contains("linux");
    }
    @Bean(name = "bossGroup")
    public EventLoopGroup bossGroup() {
        if (isLinux()) {
            log.info("linux" + EpollEventLoopGroup.class.getName());
            return new EpollEventLoopGroup(gB26875Properties.getBossThreads());
        }
        return new NioEventLoopGroup(gB26875Properties.getBossThreads());
    }


    @Bean(name = "workerGroup")
    public EventLoopGroup workerGroup() {
        if (isLinux()) {
            return new EpollEventLoopGroup(gB26875Properties.getWorkerThreads());
        }
        return new NioEventLoopGroup(gB26875Properties.getWorkerThreads());
    }


    @Bean(name = "businessGroup")
    public EventExecutorGroup businessGroup() {
        if (isLinux()) {
            return new EpollEventLoopGroup(gB26875Properties.getBusinessThreads());
        }
        return new NioEventLoopGroup(gB26875Properties.getBusinessThreads());
    }

}
